home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 3791 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.1 KB  |  53 lines

  1. Path: andrew.cmu.edu!cn0v+
  2. From: Chie B Ng <cn0v+@andrew.cmu.edu>
  3. Newsgroups: comp.lang.c
  4. Subject: array passing problem
  5. Date: Wed, 31 Jan 1996 01:27:16 -0500
  6. Organization: Fifth yr. senior, Mathematics, Carnegie Mellon, Pittsburgh, PA
  7. Message-ID: <cl3kj4C00bkWMWlEJH@andrew.cmu.edu>
  8. NNTP-Posting-Host: po8.andrew.cmu.edu
  9.  
  10. Hello, sorry to bother you, but I can not see what the problem is with
  11. this code fragment.  When I use gcc -ansi to compile this I receive this
  12. message: "warning: passing arg 1 of 'average' from incompatible pointer
  13. type".  When I run it, I get a segmentation fault in the average
  14. procedure.  Thanks.
  15.  
  16.  
  17. /* headers go here.... */
  18.  
  19. typedef unsigned char pixel;
  20.  
  21. double average(pixel **a, int rows, int columns)
  22. {
  23.     int i, j, sum = 0;
  24.  
  25.     /* since char is an int, there is no problem with + */
  26.  
  27.     for (i = 0 ; i < rows ; i++)
  28.         for (j = 0 ; j < columns ; j++)
  29.             sum += a[i][j];
  30.  
  31.     return ((double)sum)/(rows*columns);
  32. }
  33.     
  34.  
  35. void main(int argc, char **argv[])
  36. {
  37.     double avg;
  38.     pixel image[200][100];
  39.  
  40.     /* initialize image with values */
  41.     /* .... */
  42.  
  43.     avg = average(image, 200, 100);
  44.  
  45.     printf("%f", avg);
  46.  
  47.     exit(0);
  48. }
  49.     
  50.  
  51.   
  52.  
  53.